/**
 * 
 */
package niuke.wangyi;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author zhongfang
 *
 */
public class test4 {

	static class SameSum {
		int sum;
		ArrayList<ArrayList<Integer>> list = new ArrayList<>();

		public boolean add(SameSum sameSum, int i) {
			boolean added = false;
			for (ArrayList<Integer> arrayList : sameSum.list) {
				if (!arrayList.contains(i)) {
					added = true;
					ArrayList<Integer> integers = new ArrayList<>(arrayList);
					integers.add(i);
					list.add(integers);
				}
			}
			return added;
		}

		public void add(int i) {// 这一个数值的和为i
			ArrayList<Integer> integers = new ArrayList<>();
			integers.add(i);
			list.add(integers);
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		int m = scanner.nextInt();
		// Arrays.sort(a);
		// boolean[] used = new boolean[n];
		// System.out.println(helper(a, m, used));
		System.out.println(minCoins3(a, m));
	}

	private static long helper(int[] a, int m, boolean[] used) {
		if (m == 0) {
			return 1;
		}
		long max = -1;
		for (int i = 0; i < a.length; i++) {
			if (m >= a[i]) {
				if (!used[i]) {
					used[i] = true;
					long tmp = helper(a, m - a[i], used);
					max = Math.max(tmp * a[i], max);
					used[i] = false;
				}
			} else {
				break;
			}
		}
		return max;
	}

	public static int minCoins3(int[] a, int m) {
		if (a == null || a.length == 0 || m < 0) {
			return -1;
		}
		int n = a.length;
		int notExist = -1;// 初始化为不存在（最小）
		int[][] dp = new int[n + 1][m + 1];

		for (int j = 0; j < m + 1; j++) {
			if (j == a[0] && j <= m) {
				dp[0][a[0]] = a[0];
			} else {
				dp[0][j] = notExist;
			}

		}
		for (int i = 1; i < n; i++) {
			for (int j = m; j >= a[i]; j--) {
				dp[i][j] = dp[i - 1][j];
				if (j - a[i] >= 0 && dp[i - 1][j - a[i]] != notExist) {
					dp[i][j] = Math.max(dp[i - 1][j - a[i]] * a[i], dp[i][j]);
				}
			}
		}
		return dp[n - 1][m];
	}
}
